﻿using B.S.Data.MES.API.Applications.AssignattributesOneApplications;
using B.S.Data.MES.API.Applications.ProcessmaintenanceApplications.Command;
using B.S.Domain.Process.AssignattributesOneModel;
using B.S.Domain.Process.ProcessmaintenanceModel;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.ProcessmaintenanceApplications.Horter
{
    public class AddProcessmaintenanceCommandHorter:IRequestHandler<AddProcessmaintenanceCommand,APIRequst<int>>
    {
        IBaseRepository<Processmaintenance> repository;

        public AddProcessmaintenanceCommandHorter(IBaseRepository<Processmaintenance> repository)
        {
            this.repository = repository;
        }

        public async Task<APIRequst<int>> Handle(AddProcessmaintenanceCommand request, CancellationToken cancellationToken)
        {
            var tracebackInfo = new Processmaintenance
            {
                ProcessmaintenanceEncode = request.ProcessmaintenanceEncode,
                ProcessmaintenanceName = request.ProcessmaintenanceName,
                ProcessmaintenanceType = request.ProcessmaintenanceType,
                ProcessmaintenanceReportingmode = request.ProcessmaintenanceReportingmode,
            ProcessmaintenanceDescription = request.ProcessmaintenanceDescription,


            };
            // 保存到数据库
            var result = await repository.Add(tracebackInfo);
            return new APIRequst<int>()
            {

                Data = result,
                Msg = "添加成功"
            };
        }
    }
}
